﻿using System.Web.Mvc;
using ControleRepresentante.Logic.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WebSite.Controllers;

namespace ControleRepresentante.UnitTests.Controllers
{
    [TestClass]
    public class ConfiguracoesControllerTests : TestScenario
    {
        private ConfiguracoesController m_ConfiguracoesController;
        const string RepresentanteNome = "repre";
        const string Username = "u";

        protected override void Initialize()
        {
            base.Initialize();
            this.LoginAsAdmin();
            this.CreateRepresentante(RepresentanteNome, true, Username);
            this.Logout();
            this.LoginAs(Username);
            m_ConfiguracoesController = new ConfiguracoesController(RepositoryProvider, ControllerExtensionProvider);
        }

        [TestMethod]
        public void TestDetailsPedidoData()
        {
            ActionResult actionResult = m_ConfiguracoesController.Details();
            Assert.IsInstanceOfType(actionResult, typeof(ViewResult));
            ViewResult viewResult = (ViewResult)actionResult;
            Assert.IsInstanceOfType(viewResult.Model, typeof(RepresentanteInfo));
            RepresentanteInfo representanteInfo = (RepresentanteInfo)viewResult.Model;
            Assert.AreEqual(RepresentanteNome, representanteInfo.NomePedido);
            Assert.IsNull(representanteInfo.InfoPedido);
        }

        [TestMethod]
        public void TestEditPagePedidoData()
        {
            ActionResult actionResult = m_ConfiguracoesController.Edit();
            Assert.IsInstanceOfType(actionResult, typeof(ViewResult));
            ViewResult viewResult = (ViewResult) actionResult;
            Assert.IsInstanceOfType(viewResult.Model, typeof(RepresentanteInfo));
            RepresentanteInfo representanteInfo = (RepresentanteInfo) viewResult.Model;
            Assert.AreEqual(RepresentanteNome, representanteInfo.NomePedido);
            Assert.IsNull(representanteInfo.InfoPedido);
        }

        [TestMethod]
        public void TestEditPedidoData()
        {
            const string NomePedido = "nomepedido";
            const string InfoPedido = "infopedido";

            ActionResult actionResult = m_ConfiguracoesController.Edit(NomePedido, InfoPedido, null);
            Assert.IsInstanceOfType(actionResult, typeof(RedirectToRouteResult));
            RedirectToRouteResult redirectToRouteResult = (RedirectToRouteResult)actionResult;
            Assert.AreEqual("Details", redirectToRouteResult.RouteValues["action"]);
            actionResult = m_ConfiguracoesController.Details();
            Assert.IsInstanceOfType(actionResult, typeof(ViewResult));
            ViewResult viewResult = (ViewResult)actionResult;
            Assert.IsInstanceOfType(viewResult.Model, typeof(RepresentanteInfo));
            RepresentanteInfo representanteInfo = (RepresentanteInfo)viewResult.Model;
            Assert.AreEqual(NomePedido, representanteInfo.NomePedido);
            Assert.AreEqual(InfoPedido, representanteInfo.InfoPedido);
        }
    }
}
